<template>
<!-- 轮播板块 -->
  <div class="banner container-fluid" @mouseover="cleanautoplay" @mouseout="autoPlay">
    <!-- 轮播图 -->
    <div class="row pattern">
      <div class="col-12 imgBox">
        <div class="ul" ref="ul">
          <div ref="li" v-for="item in banner" :key="item.id" class="li" :style="'background-image:url('+item.imgsrc+')'">
          </div>
        </div>
      </div>
    </div>
    <!-- 中间 -->
    <div class="row font">
      <div class="col-8 offset-2 ">
        <p>Cereshop</p>
        <p>安全、可靠、稳定、高品质的Cereshop</p>
        <div class="bttn">查看详情</div>
      </div>
    </div>
    <!-- 底部 -->
    <floatInfo></floatInfo>
    <!-- <div class="row floatBottom justify-content-md-center">
      <div class="col-md-3 col-4  item-box " v-for="item in banner_bot" :key="item.id">
        <div class="img">
          <img :src="item.imgsrc" class="img-fluid">
        </div>
        <div class="plan d-none d-md-block">
          <div class="title">{{item.title}}</div>
          <div class="info">{{item.info}}</div>
        </div>
      </div>
    </div> -->
    <!-- 轮播按钮 -->
    <div class="row patternBtn justify-content-center">
      <div class="col-md-6 col-10 btnBox" ref="btn">
        <div class="span" v-for="item in banner" :index="item.id" :key="item.id" @mouseover.stop="change" @mouseout.stop="autoPlay"></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  components: {
      "floatInfo":()=>import('@/components/block/banner/floatInfo')
  },
  data() {
    return {
      banner: [
        { 'id': 0, 'imgsrc': 'http://cereshop.oss-cn-shenzhen.aliyuncs.com/0000/2020/08/7323626f-f91b-4ef4-891e-2931895a2eb9.png' },
        { 'id': 1, 'imgsrc': 'http://cereshop.oss-cn-shenzhen.aliyuncs.com/0000/2020/08/7323626f-f91b-4ef4-891e-2931895a2eb9.png' },
        { 'id': 2, 'imgsrc': 'http://cereshop.oss-cn-shenzhen.aliyuncs.com/0000/2020/08/7323626f-f91b-4ef4-891e-2931895a2eb9.png' },
        { 'id': 3, 'imgsrc': 'http://cereshop.oss-cn-shenzhen.aliyuncs.com/0000/2020/08/7323626f-f91b-4ef4-891e-2931895a2eb9.png' },
        { 'id': 4, 'imgsrc': 'http://cereshop.oss-cn-shenzhen.aliyuncs.com/0000/2020/08/7323626f-f91b-4ef4-891e-2931895a2eb9.png' },
        { 'id': 5, 'imgsrc': 'http://cereshop.oss-cn-shenzhen.aliyuncs.com/0000/2020/08/7323626f-f91b-4ef4-891e-2931895a2eb9.png' },
        { 'id': 6, 'imgsrc': 'http://cereshop.oss-cn-shenzhen.aliyuncs.com/0000/2020/08/7323626f-f91b-4ef4-891e-2931895a2eb9.png' },
        { 'id': 7, 'imgsrc': 'http://cereshop.oss-cn-shenzhen.aliyuncs.com/0000/2020/08/7323626f-f91b-4ef4-891e-2931895a2eb9.png' }
      ],
      auto: '',
      index: 0
    }
  },
  mounted() {
    this.$refs.btn.childNodes[0].classList.add("spanTrue")
    if (this.$refs.ul) {
      this.$refs.ul.style.width = this.banner.length * 100 + '%'
      // this.$refs.ul.childNodes.forEach(e => {
      //   e.style.width = 100 / this.banner.length + '%'
      // })
    }
    this.autoPlay()
  },
  destroyed() {
    this.cleanautoplay()
  },
  methods: {
    autoPlay() {
      // console.log("开始播放")
      this.auto = setInterval(this.play, 4000)
    },
    play() {
      if (this.index == this.banner.length - 1) {
        this.index = 0
      } else {
        this.index++
      }
      this.next()
    },

    change(e) {
      // console.log('123')
      this.cleanautoplay()
      this.index = e.currentTarget.getAttribute('index')
      this.next()
    },
    next() {
      if (this.$refs.ul) {
        this.$refs.ul.style.marginLeft = '-' + this.index * 100 + '%'
      }
      this.$refs.btn.childNodes.forEach(element => {
        element.classList.remove("spanTrue")
      })
      this.$refs.btn.childNodes.forEach(element => {
        if (element.getAttribute('index') == this.index) {
          element.classList.add("spanTrue")
        }
      })
    },
    cleanautoplay() {
      // console.log("清除")
      window.clearInterval(this.auto)
    }

  }
}
</script>

<style lang="less" scoped>
.banner {
  // overflow: hidden;
  // max-width: 100%;
  height: 40rem;
  background: linear-gradient(
    180deg,
    rgba(92, 209, 219, 1),
    rgba(92, 197, 219, 1)
  );
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  .pattern {
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    position: absolute;
    z-index: 0;
    .imgBox {
      position: relative;
      width: 100%;
      height: 100%;
      overflow: hidden;
      .ul {
        width: 800%;
        height: 100%;
        display: flex;
        transition: all 0.8s;
        .li {
          width: 100%;
          height: 40rem;
          overflow: hidden;
          background-position: center center;
          background-repeat: no-repeat;
          -webkit-background-size: cover;
          -moz-background-size: cover;
          background-size: cover;
        }
      }
    }
  }
  .font {
    display: flex;
    flex-direction: column;
    justify-content: center;
    p {
      position: relative;
      z-index: 3;
      color: #ffffff;
    }
    p:nth-child(1) {
      z-index: 3;
      font-size: 5.25rem;
      font-weight: bold;
    }
    p:nth-child(2) {
      z-index: 3;
      font-size: 1.88rem;
      font-weight: 500;
    }
    .bttn {
      margin-top: 4rem;
      width: 13.75rem;
      height: 4.25rem;
      line-height: 4.25rem;
      text-align: center;
      border: 0.05rem solid rgba(255, 255, 255, 1);
      border-radius: 0rem;
      font-size: 1.88rem;
      font-family: PingFang SC;
      font-weight: 500;
      color: #ffffff;
    }
  }
//   .floatBottom {
//     height: 8rem;
//     background-color: rgba(0, 0, 0, 0.5);
//     width: 100%;
//     position: absolute;
//     bottom: 0;
//     left: 0;
//     .item-box {
//       cursor: pointer;
//       transition: all 0.5s;
//       width: 100%;
//       display: flex;
//       justify-content: space-around;
//       align-items: center;
//       .img {
//         width: 4.38rem;
//         height: 4.38rem;
//       }
//       .plan {
//         display: flex;
//         flex-direction: column;
//         justify-content: space-between;
//         color: #ffffff;
//         .title {
//           font-size: 1.5rem;
//         }
//         .info {
//           font-size: 1rem;
//         }
//       }
//     }
//     .item-box:hover {
//       background-color: rgba(255, 255, 255, 0.5);
//     }
//   }
  .patternBtn {
    position: absolute;
    bottom: 8.5rem;
    width: 100%;
    height: 1rem;
    .btnBox {
      display: flex;
      justify-content: center;
      align-items: center;
      .span {
        width: 3rem;
        height: 40%;
        background-color: saddlebrown;
        margin: 0 0.3rem;
        background-color: rgba(255, 255, 255, 0.33);
        border-radius: 0.3rem;
        cursor: pointer;
      }
      .spanTrue {
        background-color: rgba(255, 255, 255, 1);
      }
    }
  }
}
</style>